using System;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Dispatcher;

namespace Caramel.ServiceModel
{
	public class PerCallLocalStorageCallContextInitializer : ICallContextInitializer
	{
		#region ICallContextInitializer Members

		public object BeforeInvoke(InstanceContext instanceContext, IClientChannel channel, Message message)
		{
			OperationContext.Current.Extensions.Add(new PerCallLocalStorageExtension());
			
			return null;
		}

		public void AfterInvoke(object correlationState)
		{
			//if (UnitOfWork.Current != null)
			//{
			//    UnitOfWork.Current.Flush();
			//    UnitOfWork.Current.Dispose();
			//}
		}

		#endregion
	}
}
